{% extends 'myadmin/index.html' %}

{% block title %}
<title>后台-订单列表</title>
{% endblock %}

{% block con %}
<div class="row-content am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <div class="widget-head am-cf">
                    <div class="widget-title  am-cf">订单列表</div>
                </div>
                <div class="widget-body  am-fr">

                    
                    <div>
                    <form action="">
                    <div class="am-u-sm-12 am-u-md-12 am-u-lg-9">
                        <div class="am-form-group tpl-table-list-select">
                            <select name="types" data-am-selected="{btnSize: 'sm'}" style="display: none;">
                              <option value="all">所有类别</option>
       
                            </select>
                        </div>
                    </div>
                    <div class="am-u-sm-12 am-u-md-12 am-u-lg-3">
                        <div class="am-input-group am-input-group-sm tpl-form-border-form cl-p">
                            <input name='keywords'value='{{request.GET.keywords}}'type="text" class="am-form-field ">
                            <span class="am-input-group-btn">
                                <button class="am-btn  am-btn-default am-btn-success tpl-table-list-field am-icon-search" ></button>
                              </span>
                        </div>
                    </div>
                    </form>
                    </div>

                    <div class="am-u-sm-12">
                        <table width="100%" class="am-table am-table-compact am-table-striped tpl-table-black ">
                            <thead>
                                <tr>   
                                    <th>会员</th>                      
                                    <th>订单号</th>
                                    <th>收货人</th>
                                    <th>收货电话</th>
                                    <th>订单总价</th>
                                    <th>下单时间</th>
                                    <th>状态</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                {% for v in data %}
                                <tr>                                       
                                    <td>{{v.name}}</td>
                                </tr>
                                {% for vv in v.od %}
                                <tr>
                                    <td></td>
                                    <td>{{ vv.id }}</td>
                                    <td class="am-text-middle">{{ vv.buser}}</td>
                                    <td class="am-text-middle">{{ vv.buser_phone }}</td>
                                    <td class="am-text-middle">{{ vv.totalprice }}</td>
                                    <td class="am-text-middle">{{ vv.addtime }}</td>
                                    <td class="am-text-middle name">{% if vv.status == 0 %}未付款{%elif  vv.status == 1 %}待发货{%elif  vv.status == 2 %}待收货{%elif  vv.status == 3 %}待评价{%elif  vv.status == 4 %}前台删除{%endif%}</td>
                                    <td class="am-text-middle">
                                        <div class="tpl-table-black-operation">
                                            <a href="javascript:void(0)" class="edit">
                                                <i class="am-icon-pencil"></i> 修改状态
                                            </a>
                                            <a href="{% url 'myadmin_order_info' %}?id={{vv.id}}" class="tpl-table-black-operation-del">
                                                <i class="am-icon-trash"></i> 查看详情
                                            </a>
                                        </div>
                                    </td>
                                </tr>
                                {% endfor %}
                                {% endfor %}
                      
                                <!-- more data -->
                            </tbody>
                        </table>
                    </div>
                    <div class="am-u-lg-12 am-cf">

                        <div class="am-fr">
                            <ul class="am-pagination tpl-pagination">
                                {% load pagetag %}
                              
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
// 修改状态绑定单击事件
$(".edit").click(function(){
    
    alert("状态名仅限于:未付款,待发货,待收货,待评价,前台删除.")
    // 获取当前点击对象
    var e = $(this)
    // 获取当前修改订单的id
    var oid = e.parents("tr").find("td:eq(1)").text()
    // 获取当前订单状态
    var zt = e.parents("tr").find(".name").text()
    // 动态创建input输入框 放在状态位置
    var inp = $('<input value="'+zt+'" style="color:#000">')   
    e.parents("tr").find(".name").html(inp)
    inp.select()
    // 输入框绑定鼠标按下事件  触发失去焦点事件
    inp.mousedown(function(){
        // 输入框绑定鼠标失去焦点事件  
        inp.blur(function(){
            // 获取修改后名称
            var ezt = $(this).val()
            console.log(ezt)
            // 判断名称是否变化
            if(ezt == zt){
                // 恢复原样
                e.parents("tr").find(".name").html(zt)
            }else{
                var arr =["未付款","待发货","待收货","待评价","前台删除"]
                console.log(arr.indexOf(ezt))
                if(arr.indexOf(ezt) == -1){
                   alert('状态名错误')
                }else{ // 发送请求
                    $.get('{% url "myadmin_order_edit" %}',{'oid':oid,'ezt':ezt},function(data){
                        // 修改状态名
                        e.parents("tr").find(".name").html(ezt)
                        alert(data['msg'])
                    },'json')}               
            }
        })
    })
})
</script>
{% endblock %}